home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 January: Mac OS SDK / Dev.CD Jan 96 SDK / Dev.CD Jan 96 SDK1.toast / Development Kits (Disc 1) / QuickDraw™ GX / Programming Stuff / Sample Code / Graphics Samples / Pen Play ƒ / pen play.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-10  |  8.2 KB  |  270 lines  |  [TEXT/KAHL]

  1. /*
  2.     pen play.c
  3.     
  4.     This application creates various paths. We will then apply different pen styles to each path. We play with
  5.     the pen size and location of the pen (i.e. on, inset, and outside of the geometry).
  6.      
  7.     NOTES:
  8.     • This file requires the following files to run correctly:
  9.         "graphics shell.c", "Color library.c", "graphics debug library.c",  "Shape library.c", 
  10.         "Transform library.c".
  11.         
  12.     • This file prints the "best" in landscape mode.
  13.         
  14.     ©1992 - 1994  Apple Computer, Inc.
  15.     All rights reserved.
  16. */
  17.  
  18. #include <events.h>
  19. #include <windows.h>
  20.  
  21. #include "Font library.h"
  22. #include "graphics libraries.h"
  23. #include "graphics toolbox.h"
  24. #include "graphics shell.h"
  25.  
  26. //
  27. //  Set up the title and size of the window 
  28. //
  29. Str255         gWindowTitle = "\p Pen Play...";
  30. Rect         gWindowQDRect  = {40, 10, 445, 575};
  31.  
  32. //
  33. //    gGraphicsHeapSize sets the size of the graphics heap created by calling the GXNewGraphicsClient routine
  34. //    in main () within graphics shell.c.  You can determine the amount of graphics heap required by using GraphicsBug.
  35. //    With gGraphicsHeapSize set to 135k, I had 15 free blocks left in the graphics heap. Sounds good to me.
  36. //
  37. long        gGraphicsHeapSize = 135;
  38.  
  39. gxShape     gThePage;
  40.  
  41.  
  42. //
  43. //    We use "gShapesInPicture"  in the DoDraw function. If we have added shapes to the picture, we draw it. Otherwise, we
  44. //    wait for the user to click in the window, thereby adding a gxShape to the picture.
  45. //
  46. Boolean        gShapesInPicture;
  47.  
  48.  
  49.  
  50. /*------ DoInitialization ---------------------------------------------------------------------------------*/
  51.  
  52. void DoInitialization(gWindow)
  53. WindowPtr gWindow;
  54. {
  55.      gxShape     thePath;
  56.     long         tripleDumpGeometricData[] = {    1,             // number of contours 
  57.                                                   6,             // number of points
  58.                                                   0xff000000,
  59.                                                      0, 0,       // the points
  60.                                                      ff(75),  0, 
  61.                                                      ff(5), ff(50), 
  62.                                                      ff(75),  ff(100),  
  63.                                                     0,  ff(100), 
  64.                                                      ff(75), ff(50)};
  65.                                                              
  66.     long         ovalWabbleGeometricData[] = {     1,             // number of contours
  67.                                                    6,             // number of points
  68.                                                    0xff000000,
  69.                                                     0, 0,       // the points
  70.                                                     ff(150),  0, 
  71.                                                     ff(80), ff(100), 
  72.                                                     ff(150), ff(200),  
  73.                                                     0, ff(200), 
  74.                                                     ff(80), ff(100)};
  75.                                                             
  76.      long         figureEightGeometricData[] = {    1,             // number of contours
  77.                                                  6,            // number of points
  78.                                                  0xff000000,
  79.                                                    0, 0,         // the points
  80.                                                    ff(150),  0, 
  81.                                                    ff(75), ff(90), 
  82.                                                    0, ff(200), 
  83.                                                    ff(150), ff(200),  
  84.                                                    ff(75), ff(90)}; 
  85.                                                    
  86.     long         tripleEightGeometricData[] = {     1,             // number of contours
  87.                                                  6,            // number of points
  88.                                                  0xff000000,
  89.                                                    0, 0,          // the points
  90.                                                    ff(150),  0, 
  91.                                                    ff(10), ff(100), 
  92.                                                    ff(150), ff(200),  
  93.                                                   0, ff(200), 
  94.                                                    ff(150), ff(100)};        
  95.     short    loop,
  96.              newHLoc,
  97.              newPenWidth;
  98.              
  99.     InitCommonColors();
  100.  
  101.     //
  102.     //     Create the "gthePage" shape. We set the unique items attribute to make sure that each item added to the
  103.     //    picture has a unique reference. If this attribute was not set, we would not see all of the inset, outset, and on
  104.     //    geometry paths we create below.
  105.     //
  106.     gThePage = GXNewShape(gxPictureType);
  107.     GXSetShapeAttributes(gThePage, gxUniqueItemsShape);
  108.     
  109.     //
  110.     //     Create a gxPath which has: starting with a pen thickness of 0, it's gxColor is green, and it's drawn with it's frame.
  111.     //     We will then draw the gxPath 6 times with an increasing (from 2 through 14) pen width
  112.     //
  113.      newHLoc = 10;
  114.      newPenWidth = 3;
  115.                                                              
  116.     thePath = GXNewPaths((gxPaths *) tripleDumpGeometricData);
  117.     GXSetShapeFill (thePath, gxClosedFrameFill);
  118.      SetShapeCommonColor (thePath, blue);
  119.  
  120.     for (loop = 0; loop  < 8; loop ++) 
  121.     {    
  122.         GXMoveShapeTo (thePath,  ff(newHLoc), ff(15));
  123.         AddToShape(gThePage, thePath);
  124.                 
  125.         GXSetShapePen(thePath, ff(newPenWidth));
  126.                     
  127.         newPenWidth +=  2;
  128.         newHLoc += 70;
  129.     }
  130.     GXDisposeShape(thePath);  
  131.  
  132.     //
  133.     //     Create a gxPath which looks like an oval with the middle sides pushed in. We will then draw it with the the gxStyle set to: 
  134.     //     gxCenterFrameStyle, gxOutsideFrameStyle, and gxInsideFrameStyle.
  135.     //                                                          
  136.     thePath = GXNewPaths((gxPaths *) ovalWabbleGeometricData);
  137.     GXSetShapeFill (thePath, gxClosedFrameFill);
  138.      GXSetShapeStyleAttributes(thePath, gxOutsideFrameStyle);                    
  139.     GXSetShapePen(thePath, ff(6));
  140.     SetShapeCommonColor (thePath, red);
  141.  
  142.     GXMoveShapeTo (thePath,  ff(10), ff(160));
  143.         
  144.     for (loop = 0; loop  < 3; loop ++) 
  145.     {    
  146.         if (loop == 1) {
  147.            GXSetShapeStyleAttributes(thePath, gxInsideFrameStyle);                    
  148.            SetShapeCommonColor (thePath, green);
  149.         }    
  150.  
  151.         if (loop == 2) {
  152.             GXSetShapePen(thePath, ff(3));
  153.             GXSetShapeStyleAttributes(thePath, gxCenterFrameStyle);                    
  154.             SetShapeCommonColor (thePath, blue);
  155.         }    
  156.                         
  157.         AddToShape(gThePage, thePath);
  158.     }
  159.     GXDisposeShape(thePath);  
  160.  
  161.     //
  162.     //     Create a gxPath which looks like a figure eight. We will then draw it with the the style set to: 
  163.     //     gxCenterFrameStyle, gxOutsideFrameStyle, and gxInsideFrameStyle.
  164.     //
  165.     thePath = GXNewPaths((gxPaths *) figureEightGeometricData);
  166.     GXSetShapeFill (thePath, gxClosedFrameFill);
  167.      GXSetShapeStyleAttributes(thePath, gxOutsideFrameStyle);                    
  168.     GXSetShapePen(thePath, ff(6));
  169.     SetShapeCommonColor (thePath, red);
  170.  
  171.     GXMoveShapeTo (thePath,  ff(155), ff(160));
  172.  
  173.     for (loop = 0; loop  < 3; loop ++) 
  174.     {    
  175.         if (loop == 1) {
  176.             GXSetShapeStyleAttributes(thePath, gxInsideFrameStyle);                    
  177.             SetShapeCommonColor (thePath, green);
  178.         }    
  179.  
  180.         if (loop == 2) {
  181.             GXSetShapePen(thePath, ff(3));
  182.             GXSetShapeStyleAttributes(thePath, gxCenterFrameStyle);                    
  183.             SetShapeCommonColor (thePath, blue);
  184.         }    
  185.                         
  186.         AddToShape(gThePage, thePath);
  187.     }
  188.     GXDisposeShape(thePath);  
  189.  
  190.     //
  191.     //     Create a gxPath which looks like a figure eight with a 3rd loop. We will then draw it with the the style set to: 
  192.     //     gxCenterFrameStyle, gxOutsideFrameStyle, and gxInsideFrameStyle.
  193.     //
  194.     thePath = GXNewPaths((gxPaths *) tripleEightGeometricData);
  195.     GXSetShapeFill (thePath, gxClosedFrameFill);
  196.      GXSetShapeStyleAttributes(thePath, gxOutsideFrameStyle);                    
  197.     GXSetShapePen(thePath, ff(6));
  198.     SetShapeCommonColor (thePath, red);
  199.  
  200.     GXMoveShapeTo (thePath,  ff(300), ff(160));
  201.  
  202.     for (loop = 0; loop  < 3; loop ++) 
  203.     {    
  204.         if (loop == 1) {
  205.            GXSetShapeStyleAttributes(thePath, gxInsideFrameStyle);                    
  206.            SetShapeCommonColor (thePath, green);
  207.         }    
  208.  
  209.         if (loop == 2) {
  210.            GXSetShapePen(thePath, ff(3));
  211.            GXSetShapeStyleAttributes(thePath, gxCenterFrameStyle);                    
  212.            SetShapeCommonColor (thePath, blue);
  213.         }    
  214.                         
  215.         AddToShape(gThePage, thePath);
  216.     }
  217.     GXDisposeShape(thePath);  
  218. }
  219.  
  220.  
  221.  
  222. /*------ DoClick ---------------------------------------------------------------------------------------*/
  223.  
  224. void DoClick( orgMouseLoc, theWindow )
  225. gxPoint        orgMouseLoc;
  226. WindowPtr     theWindow;
  227. {
  228. }
  229.  
  230.  
  231.  
  232. /*------ DoDraw ---------------------------------------------------------------------------------------*/
  233. //
  234. //    Draw the contents of "gthePage". 
  235. // 
  236. void DoDraw(gWindow)
  237. WindowPtr gWindow;
  238. {
  239.      GXDrawShape (gThePage);
  240. }
  241.  
  242.  
  243. /*------ DoDispose -------------------------------------------------------------------------------------*/
  244.  
  245. void DoDispose(gWindow)
  246. WindowPtr gWindow;
  247. {
  248.     /**  
  249.         You should always dispose of your GX graphics objects before tossing your window. Why? It's generally good 
  250.         form and this approach guarantees that everything is disposed. If you had not disposed of everything, the
  251.         call to DisposeWindow should dispose of the objects. If you are running the debugging version of the 
  252.         SecretGraphics init with notices set, you will receive a notice that you had not disposed of everything. You
  253.         can turn notices on in this file by setting gDebugging = TRUE (above).
  254.     **/
  255.     GXDisposeShape(gThePage);  
  256.      GXDisposeShape(gWindowBoundsShape);  
  257.        DisposeCommonColors();
  258.        DisposeWindow(gWindow);
  259. }
  260.     
  261.  
  262.  
  263.  
  264. /*------ DoIdle ----------------------------------------------------------------------------------------*/
  265.  
  266. void DoIdle(gWindow)
  267. WindowPtr gWindow;
  268. {
  269. }
  270.